package com.mallcloud.mall.app.controller;

import com.mallcloud.mall.app.api.entity.dto.AppCartDTO;
import com.mallcloud.mall.app.api.entity.vo.AppCartWithAmountVO;
import com.mallcloud.mall.app.service.AppShopCartItemService;
import com.mallcloud.mall.common.core.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "购物车表管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/app/shopCartItem")
public class AppCartController {
    private final AppShopCartItemService shopCartItemService;

    @ApiOperation("新增")
    @PostMapping("/save")
    public R<Boolean> save(@Validated @RequestBody AppCartDTO dto) {
        return R.ok(shopCartItemService.saveCartItem(dto));
    }

    @ApiOperation("购物车数量")
    @GetMapping("/count")
    public R<Long> count() {
        return R.ok(shopCartItemService.cartCount());
    }

    @ApiOperation("获取用户购物车信息")
    @GetMapping("/info")
    public R<AppCartWithAmountVO> info() {
        return R.ok(shopCartItemService.info());
    }
}